<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>预约餐桌</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/lib/layui/layui.js"
            charset="utf-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>

<body>
<div class="x-body">
    <form class="layui-form" onsubmit="return false;">
        <input type="hidden" id="tableId" name="tableId" value="${param.tableId}">
        <input type="hidden" id="tableInfoWorkerId" name="tableInfoWorkerId" value="${worker.workerId}">
        <div class="layui-form-item">
            <label for="workerName" class="layui-form-label">
                <span class="x-red">*</span>操作员姓名
            </label>
            <div class="layui-input-inline">
                <input type="text" id="workerName" maxlength="10" value="${worker.workerName}" name="workerName" readonly
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="tableCapacity" class="layui-form-label">
                <span class="x-red">*</span>最大容量
            </label>
            <div class="layui-input-inline">
                <input type="text" id="tableCapacity" maxlength="10" value="${param.tableCapacity}" name="tableCapacity" readonly
                       autocomplete="off" class="layui-input">
            </div>
        </div>


        <div class="layui-form-item">
            <label for="tableInfoBookName" class="layui-form-label">
                <span class="x-red">*</span>预约姓名
            </label>
            <div class="layui-input-inline">
                <input type="text" id="tableInfoBookName" maxlength="10" name="tableInfoBookName"
                       autocomplete="off" class="layui-input" required="" >
            </div>
        </div>

        <div class="layui-form-item">
            <label for="tableInfoBookPhone" class="layui-form-label">
                <span class="x-red">*</span>预约电话
            </label>
            <div class="layui-input-inline">
                <input type="text" id="tableInfoBookPhone" maxlength="11" name="tableInfoBookPhone"
                       autocomplete="off" class="layui-input" required="" lay-verify="bookPhone">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>就餐人数
            </label>
            <div class="layui-input-inline">
                <input type="number" id="tableInfoNum" name="tableInfoNum" value="" required="" lay-verify="capacity" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>预约时间
            </label>
            <div class="layui-input-inline">
                <div class="layui-form">
                    <div class="layui-input-inline">
                        <input type="text" id="tomTime" class="layui-input" name="tomTime" value="">
                        <input type="text" id="bookTime" name="bookTime" required="" readonly class="layui-input" placeholder="请选择时间">
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">
            </label>
            <button class="layui-btn" lay-filter="add" lay-submit="">
                预约
            </button>
        </div>

    </form>
</div>
<script>


    function showTime() {
        nowtime = new Date();
        year = nowtime.getFullYear();
        month = nowtime.getMonth() + 1;
        date = nowtime.getDate();
        if (month<10){
            month = "0"+month;
        }
        if (date<10){
            date = "0"+date;
        }
        todTime=year + "-" + month + "-" + date;
        tmptime=Date.parse(new Date(todTime))/1000+86400
        var tmpdate=new Date(parseInt(tmptime)*1000)
        newyear=tmpdate.getFullYear();
        newmonth = tmpdate.getMonth() + 1;
        newdate = tmpdate.getDate();
        if (newmonth < 10) {
            newmonth = "0" + newmonth;
        }
        if (newdate < 10) {
            newdate = "0" + newdate;
        }

        $('#tomTime').val(newyear + "-" + newmonth + "-" + newdate);

    }
    setInterval("showTime()", 1000);

    layui.use(['form', 'layer','laydate'], function () {
        $ = layui.jquery;
        var form = layui.form
            , layer = layui.layer;
        var laydate = layui.laydate;


        //限定可选时间
        laydate.render({
            elem: '#bookTime'
            ,type: 'time'
            ,min: '08:00:00'
            // ,max: '03:00:00'
            ,btns: [ 'confirm','clear']
            ,trigger: 'click'
        });

        //自定义验证规则
        form.verify({
            capacity:function(value){
                if(value <= 0){
                    return '人数必须为正数';
                }
            },
            bookPhone: [/^1[0-9]{10}/,'请输入正确的电话号码']
        });

        //监听提交
        form.on('submit(add)', function (data) {
            //发异步，把数据提交给java
            $.ajax({
                type: "post",
                url: "${pageContext.request.contextPath}/foreground?m=bookTable",
                data: data.field,
                dataType: "json",
                success: function (data) {
                    layer.msg(data.msg, function () {
                        if (data.code === 200) {
                            // 数据重载
                            window.parent.location.reload();
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        }
                    });

                }
            });

        });


    });


</script>

</body>

</html>